package com.wisezone.HomeWork.home05;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 *网络通讯的第一个要素：IP地址，唯一的定位，通过IP地址，唯一的定位一台主机
 * InetAddress 位于java.net这个包下
 * 1.InetAddress用来代表Ip地址，一个InetAddress对象就代表一个IP地址
 * 2.如何创建InetAddress的对象，InetAddress。getByName("");
 * 3.   getHostName()用来获取IP地址对应的域名
 *      getHostAddress()用来获取IP地址
 *
 */

public class TestIntetAddress {
    public static void main(String[] args) {
        try {
            //创建InetAddress的对象
            InetAddress inet = InetAddress.getByName("localhost");
            System.out.println(inet);
            //两个方法
            System.out.println(inet.getHostName());
            System.out.println(inet.getHostAddress());
            //获取本机的IP
            InetAddress inet1 = InetAddress.getLocalHost();
            System.out.println(inet1);
        }catch (UnknownHostException e){
            //TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
